# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=whatweb
pkgver=v0.6.3.r10.gc42e1b9
pkgrel=1
epoch=1
groups=('blackarch' 'blackarch-recon' 'blackarch-webapp')
pkgdesc='Next generation web scanner that identifies what websites are running.'
arch=('any')
url='http://www.morningstarsecurity.com/research/whatweb'
license=('GPL')
depends=('ruby' 'ruby-bundler' 'ruby-addressable' 'libxslt')
makedepends=('git')
source=("$pkgname::git+https://github.com/urbanadventurer/WhatWeb.git")
install="$pkgname.install"
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  # tmp fix until https://github.com/urbanadventurer/WhatWeb/pull/415 merged
  echo "gem 'getoptlong', '~> 0.1'" >> Gemfile
  echo "gem 'resolv-replace', '~> 0.1'" >> Gemfile
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" \
    CHANGELOG.md README.md INSTALL.md
  install -Dm 644 "$pkgname.1" "$pkgdir/usr/share/man/man1/$pkgname.1"
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm *.md "$pkgname.1" LICENSE

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  # need to cd to load .bundle/
  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec bundle exec ruby $pkgname "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

